#
# get_files.py
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
import sys
import os
import os.path
import re

def get_files_list(dir, sources_template=None, exclude_templates_list=None):
	assert os.path.exists(dir)
	if isinstance(exclude_templates_list, basestring):
		exclude_templates_list = [exclude_templates_list]
	ok_file_re = re.compile(sources_template)
	files = [f for f in os.listdir(dir) if os.path.isfile(dir+'/'+f) and ok_file_re.findall(f)]
	for template in exclude_templates_list:
		bad = re.compile(template)
		files = [f for f in files if not bad.findall(f)]
	for i in range( len(files) ):
		files[i] = dir + '/' + files[i]
	return files

